home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / BufferedReader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  3.6 KB  |  341 lines

  1. package java.io;
  2.  
  3. public class BufferedReader extends Reader {
  4.    // $FF: renamed from: in java.io.Reader
  5.    private Reader field_0;
  6.    // $FF: renamed from: cb char[]
  7.    private char[] field_1;
  8.    private int nChars;
  9.    private int nextChar;
  10.    private static final int INVALIDATED = -2;
  11.    private static final int UNMARKED = -1;
  12.    private int markedChar;
  13.    private int readAheadLimit;
  14.    private boolean skipLF;
  15.    private boolean markedSkipLF;
  16.    private static int defaultCharBufferSize = 8192;
  17.    private static int defaultExpectedLineLength = 80;
  18.  
  19.    public BufferedReader(Reader var1, int var2) {
  20.       super(var1);
  21.       this.markedChar = -1;
  22.       this.readAheadLimit = 0;
  23.       this.skipLF = false;
  24.       this.markedSkipLF = false;
  25.       if (var2 <= 0) {
  26.          throw new IllegalArgumentException("Buffer size <= 0");
  27.       } else {
  28.          this.field_0 = var1;
  29.          this.field_1 = new char[var2];
  30.          this.nextChar = this.nChars = 0;
  31.       }
  32.    }
  33.  
  34.    public BufferedReader(Reader var1) {
  35.       this(var1, defaultCharBufferSize);
  36.    }
  37.  
  38.    private void ensureOpen() throws IOException {
  39.       if (this.field_0 == null) {
  40.          throw new IOException("Stream closed");
  41.       }
  42.    }
  43.  
  44.    private void fill() throws IOException {
  45.       int var1;
  46.       if (this.markedChar <= -1) {
  47.          var1 = 0;
  48.       } else {
  49.          int var2 = this.nextChar - this.markedChar;
  50.          if (var2 >= this.readAheadLimit) {
  51.             this.markedChar = -2;
  52.             this.readAheadLimit = 0;
  53.             var1 = 0;
  54.          } else {
  55.             if (this.readAheadLimit <= this.field_1.length) {
  56.                System.arraycopy(this.field_1, this.markedChar, this.field_1, 0, var2);
  57.                this.markedChar = 0;
  58.                var1 = var2;
  59.             } else {
  60.                char[] var3 = new char[this.readAheadLimit];
  61.                System.arraycopy(this.field_1, this.markedChar, var3, 0, var2);
  62.                this.field_1 = var3;
  63.                this.markedChar = 0;
  64.                var1 = var2;
  65.             }
  66.  
  67.             this.nextChar = this.nChars = var2;
  68.          }
  69.       }
  70.  
  71.       int var4;
  72.       do {
  73.          var4 = this.field_0.read(this.field_1, var1, this.field_1.length - var1);
  74.       } while(var4 == 0);
  75.  
  76.       if (var4 > 0) {
  77.          this.nChars = var1 + var4;
  78.          this.nextChar = var1;
  79.       }
  80.  
  81.    }
  82.  
  83.    public int read() throws IOException {
  84.       synchronized(this.lock) {
  85.          this.ensureOpen();
  86.  
  87.          while(true) {
  88.             if (this.nextChar >= this.nChars) {
  89.                this.fill();
  90.                if (this.nextChar >= this.nChars) {
  91.                   return -1;
  92.                }
  93.             }
  94.  
  95.             if (!this.skipLF) {
  96.                break;
  97.             }
  98.  
  99.             this.skipLF = false;
  100.             if (this.field_1[this.nextChar] != '\n') {
  101.                break;
  102.             }
  103.  
  104.             ++this.nextChar;
  105.          }
  106.  
  107.          return this.field_1[this.nextChar++];
  108.       }
  109.    }
  110.  
  111.    private int read1(char[] var1, int var2, int var3) throws IOException {
  112.       if (this.nextChar >= this.nChars) {
  113.          if (var3 >= this.field_1.length && this.markedChar <= -1 && !this.skipLF) {
  114.             return this.field_0.read(var1, var2, var3);
  115.          }
  116.  
  117.          this.fill();
  118.       }
  119.  
  120.       if (this.nextChar >= this.nChars) {
  121.          return -1;
  122.       } else {
  123.          if (this.skipLF) {
  124.             this.skipLF = false;
  125.             if (this.field_1[this.nextChar] == '\n') {
  126.                ++this.nextChar;
  127.                if (this.nextChar >= this.nChars) {
  128.                   this.fill();
  129.                }
  130.  
  131.                if (this.nextChar >= this.nChars) {
  132.                   return -1;
  133.                }
  134.             }
  135.          }
  136.  
  137.          int var4 = Math.min(var3, this.nChars - this.nextChar);
  138.          System.arraycopy(this.field_1, this.nextChar, var1, var2, var4);
  139.          this.nextChar += var4;
  140.          return var4;
  141.       }
  142.    }
  143.  
  144.    public int read(char[] var1, int var2, int var3) throws IOException {
  145.       synchronized(this.lock) {
  146.          this.ensureOpen();
  147.          if (var2 >= 0 && var2 <= var1.length && var3 >= 0 && var2 + var3 <= var1.length && var2 + var3 >= 0) {
  148.             if (var3 == 0) {
  149.                return 0;
  150.             } else {
  151.                int var5 = this.read1(var1, var2, var3);
  152.                if (var5 <= 0) {
  153.                   return var5;
  154.                } else {
  155.                   while(var5 < var3 && this.field_0.ready()) {
  156.                      int var6 = this.read1(var1, var2 + var5, var3 - var5);
  157.                      if (var6 <= 0) {
  158.                         break;
  159.                      }
  160.  
  161.                      var5 += var6;
  162.                   }
  163.  
  164.                   return var5;
  165.                }
  166.             }
  167.          } else {
  168.             throw new IndexOutOfBoundsException();
  169.          }
  170.       }
  171.    }
  172.  
  173.    String readLine(boolean var1) throws IOException {
  174.       StringBuffer var2 = null;
  175.       synchronized(this.lock) {
  176.          this.ensureOpen();
  177.          boolean var5 = var1 || this.skipLF;
  178.  
  179.          while(true) {
  180.             if (this.nextChar >= this.nChars) {
  181.                this.fill();
  182.             }
  183.  
  184.             if (this.nextChar >= this.nChars) {
  185.                if (var2 != null && var2.length() > 0) {
  186.                   return var2.toString();
  187.                }
  188.  
  189.                return null;
  190.             }
  191.  
  192.             boolean var6 = false;
  193.             char var7 = 0;
  194.             if (var5 && this.field_1[this.nextChar] == '\n') {
  195.                ++this.nextChar;
  196.             }
  197.  
  198.             this.skipLF = false;
  199.             var5 = false;
  200.  
  201.             int var8;
  202.             for(var8 = this.nextChar; var8 < this.nChars; ++var8) {
  203.                var7 = this.field_1[var8];
  204.                if (var7 == '\n' || var7 == '\r') {
  205.                   var6 = true;
  206.                   break;
  207.                }
  208.             }
  209.  
  210.             int var3 = this.nextChar;
  211.             this.nextChar = var8;
  212.             if (var6) {
  213.                String var9;
  214.                if (var2 == null) {
  215.                   var9 = new String(this.field_1, var3, var8 - var3);
  216.                } else {
  217.                   var2.append(this.field_1, var3, var8 - var3);
  218.                   var9 = var2.toString();
  219.                }
  220.  
  221.                ++this.nextChar;
  222.                if (var7 == '\r') {
  223.                   this.skipLF = true;
  224.                }
  225.  
  226.                return var9;
  227.             }
  228.  
  229.             if (var2 == null) {
  230.                var2 = new StringBuffer(defaultExpectedLineLength);
  231.             }
  232.  
  233.             var2.append(this.field_1, var3, var8 - var3);
  234.          }
  235.       }
  236.    }
  237.  
  238.    public String readLine() throws IOException {
  239.       return this.readLine(false);
  240.    }
  241.  
  242.    public long skip(long var1) throws IOException {
  243.       if (var1 < 0L) {
  244.          throw new IllegalArgumentException("skip value is negative");
  245.       } else {
  246.          synchronized(this.lock) {
  247.             this.ensureOpen();
  248.  
  249.             long var4;
  250.             for(var4 = var1; var4 > 0L; this.nextChar = this.nChars) {
  251.                if (this.nextChar >= this.nChars) {
  252.                   this.fill();
  253.                }
  254.  
  255.                if (this.nextChar >= this.nChars) {
  256.                   break;
  257.                }
  258.  
  259.                if (this.skipLF) {
  260.                   this.skipLF = false;
  261.                   if (this.field_1[this.nextChar] == '\n') {
  262.                      ++this.nextChar;
  263.                   }
  264.                }
  265.  
  266.                long var6 = (long)(this.nChars - this.nextChar);
  267.                if (var4 <= var6) {
  268.                   this.nextChar = (int)((long)this.nextChar + var4);
  269.                   var4 = 0L;
  270.                   break;
  271.                }
  272.  
  273.                var4 -= var6;
  274.             }
  275.  
  276.             return var1 - var4;
  277.          }
  278.       }
  279.    }
  280.  
  281.    public boolean ready() throws IOException {
  282.       synchronized(this.lock) {
  283.          this.ensureOpen();
  284.          if (this.skipLF) {
  285.             if (this.nextChar >= this.nChars && this.field_0.ready()) {
  286.                this.fill();
  287.             }
  288.  
  289.             if (this.nextChar < this.nChars) {
  290.                if (this.field_1[this.nextChar] == '\n') {
  291.                   ++this.nextChar;
  292.                }
  293.  
  294.                this.skipLF = false;
  295.             }
  296.          }
  297.  
  298.          return this.nextChar < this.nChars || this.field_0.ready();
  299.       }
  300.    }
  301.  
  302.    public boolean markSupported() {
  303.       return true;
  304.    }
  305.  
  306.    public void mark(int var1) throws IOException {
  307.       if (var1 < 0) {
  308.          throw new IllegalArgumentException("Read-ahead limit < 0");
  309.       } else {
  310.          synchronized(this.lock) {
  311.             this.ensureOpen();
  312.             this.readAheadLimit = var1;
  313.             this.markedChar = this.nextChar;
  314.             this.markedSkipLF = this.skipLF;
  315.          }
  316.       }
  317.    }
  318.  
  319.    public void reset() throws IOException {
  320.       synchronized(this.lock) {
  321.          this.ensureOpen();
  322.          if (this.markedChar < 0) {
  323.             throw new IOException(this.markedChar == -2 ? "Mark invalid" : "Stream not marked");
  324.          } else {
  325.             this.nextChar = this.markedChar;
  326.             this.skipLF = this.markedSkipLF;
  327.          }
  328.       }
  329.    }
  330.  
  331.    public void close() throws IOException {
  332.       synchronized(this.lock) {
  333.          if (this.field_0 != null) {
  334.             this.field_0.close();
  335.             this.field_0 = null;
  336.             this.field_1 = null;
  337.          }
  338.       }
  339.    }
  340. }
  341.